# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj1.py
# @Time     : 2024/4/14 20:03
# @Author   : Robot-Zsj
"""
description:

i:
5
8
2
10
5
7

0:
19
"""
from functools import lru_cache

n = int(input())

pizza = []
for _ in range(n):
    pizza.append(int(input()))


def check(idx):
    if idx < 0:
        idx = n - 1
    elif idx >= n:
        idx = 0
    return idx


@lru_cache
def recursive(l, r):
    if pizza[l] > pizza[r]:
        l = check(l - 1)
    else:
        r = check(r + 1)

    if l == r:
        return pizza[l]
    else:
        return max(recursive(check(l - 1), r) + pizza[l], recursive(l, check(r + 1)) + pizza[r])


def getResult():
    ans = 0

    for i in range(n):
        ans = max(ans, recursive(check(i - 1), check(i + 1) + pizza[i]))

    return ans


print(getResult())
